<!-- 工艺文件 -->
<template style="height:100%;">
  <div class="app-container" style="height:100%;">
    <el-card class="box-card">
      <div class="search-and-button">
        <el-button type="primary" size="small" icon="el-icon-search" @click="getTableInfo()">查询</el-button>
      </div>
      <el-row class="table">
        <el-table ref="tableData" v-loading="loading" :data="tableData" stripe border>
          <el-table-column type="selection" align="center"></el-table-column>
          <el-table-column align="center" type="index" label="索引" width="60px" />
          <el-table-column v-for="item in fieldList" :key="item.id" :align="item.align || 'left'" :prop="item.code.split(':')[1]" :label="item.val" :min-width="item.width + 'px'" show-overflow-tooltip>
            <template #default="{ row }">
              <div v-if="item.code.split(':')[1] === 'file'" class="chao">{{row.file}}</div>
              <span v-else>{{ row[item.code.split(':')[1]] }}</span>
            </template>
          </el-table-column>
        </el-table>
      </el-row>

      <el-row>
        <div class="table-btn-box">
          <el-button @click="
            () => {
              tableData.forEach(row => {
                $refs['tableData'].toggleRowSelection(row, true)
              })
            }
          ">选择全部</el-button>
          <el-button @click="
            () => {
              tableData.forEach(row => {
                $refs['tableData'].toggleRowSelection(row)
              })
            }
          ">反向选择</el-button>
          <el-button>
            更多菜单
            <i class="el-icon-arrow-down el-icon--right"></i>
          </el-button>
        </div>
        <pagination ref="Pagination" :total="total" :current.sync="search.current" :size.sync="search.size" @pagination="getTableInfo" />
      </el-row>
    </el-card>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination'
export default {
  components: { Pagination },
  data() {
    return {
      loading: false,
      tableData: [],
      total: 0,
      search: {
        current: 1,
        size: 20,
        keyword: '',
        beginDate: '',
        endDate: '',
        time: []
      }
    }
  },
  computed: {},
  created() {},
  mounted() {
    this.getTableInfo()
  },
  methods: {
    /**
     * @description: page
     * @param {*} page
     * @return {*}
     */
    async getTableInfo(page = 1) {
      this.search.current = page
      const { time } = this.search
      if (time && time.length) {
        this.search.beginDate = time[0]
        this.search.endDate = time[1]
      } else {
        this.search.beginDate = ''
        this.search.endDate = ''
      }
      const search = {
        ...this.search
      }
      delete search.time
      this.loading = true
      const res = await this.$axios.post('/pro/route/list', this.search)
      if (res?.data.code === 200) {
        this.tableData = res.data.data.list
        this.total = res.data.data.total
        setTimeout(() => {
          this.loading = false
        }, 100)
      } else {
        this.loading = false
      }
    }
  }
}
</script>
<style lang='scss' scoped>
.search-and-button {
  width: 100%;
  min-height: 27px;
  line-height: 27px;
  height: 27px;
  overflow: hidden;
  transition: height 0.3s;
  display: flex;
  justify-content: right;
}
.table {
  margin-top: 20px;
}
.chao {
  text-decoration: underline;
  color: blue;
}
</style>
